//#version 120
precision mediump float;
varying vec2 vTextuewCood;//着色器数据
varying vec4 vAmbient;//环境光
varying vec4 vDiffuse;// 散射光
varying vec4 vSpecular;// 镜面光
uniform sampler2D vDay;// 白天
uniform sampler2D vNight;// 黑夜
void main() {

    vec4 mColorDay;
    vec4 mColorNight;
    mColorDay = texture2D(vDay, vTextuewCood);
    mColorNight = texture2D(vNight, vTextuewCood);
    mColorDay = mColorDay * vAmbient + mColorDay * vDiffuse + mColorDay * vSpecular;
    mColorNight = mColorNight * vAmbient + mColorNight * vDiffuse + mColorNight * vSpecular;
    //计算当前光源的分界点
    if (vDiffuse.x > 0.21)
    {
        gl_FragColor = mColorDay;
    }
    else if (vDiffuse.x < 0.05)
    {
        gl_FragColor = mColorNight;
    }
    else
    {
        float mLight = (vDiffuse.x - 0.05)/0.16;
        gl_FragColor = mLight * mColorDay + ( 1.0 - mLight) * mColorNight;
    }


}
